﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                { display: '编号', name: 'Id', sortable: true, hide: true, align: 'left', iskey: true },
                { display: '审核状态编码', name: 'AuditStatus', sortable: false, hide: true, align: 'left' },
                { display: '项目编号', name: 'BiaoNo', width: "12%", sortable: false, align: 'left' },
                { display: '项目标题', name: 'ProjectName', width: "15%", sortable: false, align: 'left' },
                { display: '项目分类', name: 'ProjectClassName', width: "7%", sortable: false, align: 'left' },
                { display: '发布者', name: 'MemberName', width: "5%", sortable: false, align: 'left' },
                { display: '筹资金额(元)', name: 'Amount', width: "7%", sortable: false, align: 'left' },
                { display: '筹集天数', name: 'CollectDays', width: "7%", sortable: false, align: 'left' },
                { display: '创建时间', name: 'AddTime', width: "7%", sortable: false, align: 'left' },
                { display: '审核状态', name: 'AuditStatusName', width: "5%", sortable: false, hide: false, align: 'left' },
                //{ display: '项目状态', name: 'ProjectStatus', width: "7%", sortable: false, hide: false, align: 'left' },
                //{ display: '投资查询', name: 'Id', width: "10%", sortable: false, align: 'left', process: processOp1 },
                { display: '操作', name: 'Id', width: "10%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        
        function processOp1(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='投资档位' href='javascript:;'  onclick=\"util.Item('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资档位</a>");
            ops.push("&nbsp;<a title='投资详情' href='javascript:;'  onclick=\"util.InvestmentDetails('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资详情</a>"); 
            return ops.join("");
        }
        function processOp(value, cell) { 
            var ops = [];
            ops.push("&nbsp;<a title='预览' href='/Default/Detail/" + value + "' target='_blank'\"><i class='fa fa-edit' class='fa fa-trash-o'></i>预览</a>");
            ops.push("&nbsp;<a title='投资档位' href='javascript:;'  onclick=\"util.Item('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资档位</a>");

            if (cell[7] == "5") {
                ops.push("&nbsp;<a title='满标' href='javascript:;'  onclick=\"util.ManBiao('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>满标</a>");
                ops.push("&nbsp;<a title='流标' href='javascript:;'  onclick=\"util.LiuBiao('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>流标</a>");
                ops.push("&nbsp;<a title='第一次付款' href='javascript:;'  onclick=\"util.Loen('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>第一次付款</a>");
                ops.push("&nbsp;<a title='第二次付款' href='javascript:;'  onclick=\"util.Loen1('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>第二次付款</a>");
            } else {
                
                if (cell[1] == "200") {
                    ops.push("&nbsp;<a title='发布' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>发布</a>");
                } else if (cell[2] == "210") {
                    ops.push("&nbsp;<a title='撤回' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>撤回</a>");
                    ops.push("&nbsp;<a title='投资详情' href='javascript:;'  onclick=\"util.InvestmentDetails('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资详情</a>");
                }else
                {
                    ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>审核</a>"); 
                }

            }
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });

       /* $("#btnAdd").click(function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        });*/
        //投资档位
        util.Item = function (id) {
            var url = options.itemUrl + "/" + id;
            location.href = url;
        };

        //投资详情
        util.InvestmentDetails = function (id) {
            var url = options.investmentDetailsUrl + "/" + id;
            location.href = url;
        };
        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };

        util.Auditing = function(id) {
            var url = options.auditingUrl + "/" + id;
            location.href = url;
        };

        util.Delete = function(id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                function(res) {
                    if (res.Status > 0) {
                        alert("操作成功！");
                        xjgrid.Reload();
                    } else {
                        alert("操作失败！");
                    }
                },
                "json"
            );
        };
       
        //满标
        util.ManBiao = function (id) {
            if (!confirm("您确定要满标吗？这可是要负责的额。")) {
                return false;
            }
            $.ajax({
                url: "/ProjectMgr/ManBiao",
                type: "Post",
                success: function (data) {
                    var obj = JSON.parse(data);
                    alert(obj.errorMessage);
                    xjgrid.Reload();
                },
                data: "projectId=" + id + "&eventType=2"
            });
        };

        //流标
        util.LiuBiao = function (id) {
            if (!confirm("您确定要流标吗？这可是要负责的额。")) {
                return false;
            }
            $.ajax({
                url: "/ProjectMgr/ManBiao",
                type: "Post",
                success: function (data) {
                    var obj = JSON.parse(data);
                    alert(obj.errorMessage);
                    xjgrid.Reload();
                },
                data: "projectId=" + id + "&eventType=1"
            });
        };

        util.Loen = function (id) {
            if (!confirm("您确定分标放款吗?")) {
                return false;
            }
            $.ajax({
                url: "/ProjectMgr/FenBiao",
                type: "Post",
                success: function (data) {
                    var obj = JSON.parse(data);
                    alert(obj.errorMessage);
                    xjgrid.Reload();
                },
                data: "projectId=" + id + "&origOrderType=1"
            });
        };
 
        util.Loen1 = function (id) {
            if (!confirm("您确定分标放款吗。")) {
                return false;
            }
            $.ajax({
                url: "/ProjectMgr/FenBiao",
                type: "Post",
                success: function (data) {
                    var obj = JSON.parse(data);
                    alert(obj.errorMessage);
                    xjgrid.Reload();
                },
                data: "projectId=" + id + "&origOrderType=2"
            });
        };
    });

})(window, undefined, jQuery);